//
//  CoreDataEntity.h
//  UESTCPioneer
//
//  Created by Apple on 14-11-15.
//  Copyright (c) 2014年 Sway. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "SubPartyEntity.h"
#import "BranchEntity.h"
#import "UserInfoEntity.h"
#import "SingleTon.h"

@interface CoreDataEntity : NSObject
single_interface(CoreDataEntity)

@property (nonatomic,strong) NSManagedObjectContext * context;

//格式化数据
+(void)branchEntityFromDictionary:(NSDictionary *)dict context:(NSManagedObjectContext *)context;

+(void)userFromDictionary:(NSDictionary*)aDic context:(NSManagedObjectContext *)context;

+(void)subPartyEntityFromDictionary:(NSDictionary*)aDic context:(NSManagedObjectContext *)context;

//打开数据库
+(NSManagedObjectContext *)openDB;

//保存数据
+(void)saveNewBranch:(BranchEntity *)entity context:(NSManagedObjectContext *)context;
+(void)saveNewSubParty:(SubPartyEntity *)entity context:(NSManagedObjectContext *)context;
+(void)saveNewUserInfo:(UserInfoEntity *)userInfo context:(NSManagedObjectContext *)context;

//查询数据
+(UserInfoEntity*)getUserByUserId:(NSString*)userId;
+(NSMutableArray *)selectAllUserInfo;
+(NSArray *)selectAllSubParty;
+(NSMutableArray *)selectAllUserInfoWithPartyId:(NSString *)partyId;
+(NSArray*)fetchAllBranchsWithContext:(NSManagedObjectContext *)context;
+(NSArray *)getSubPartyByInstiNo:(NSString*)instiNo  context:(NSManagedObjectContext *)context;
+(NSArray*)getUsersByPartyNo:(NSString*)partyNo  context:(NSManagedObjectContext *)context;
+(NSString *)selectUserNameWithUserId:(NSString *)userId;

//检查数据表是否创建
+(BOOL)haveCreateBranchAndSubPartyWithContext:(NSManagedObjectContext *)context;
+(BOOL)haveSaveUserByUserId:(NSString *)userId context:(NSManagedObjectContext *)context;
@end
